//
//  CommandViewController.m
//  ZCooking
//
//  Created by 韩旭 on 16/8/27.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "CommandViewController.h"
#import "HX_Macro.h"
#import "HXCommandCustomCell.h"
#import "HXNewPersonVC.h"
#import "HXFoodMadeVC.h"
#import "HXGuessLikeVC.h"
#import "HXScenceMenuVC.h"
#import "HXSearchBtnVC.h"
#import "UIView+Frame.h"
#import "HX_CycleImage.h"
#import "HXNetTool.h"
#import "HXFoodCycleModel.h"
#import "HXTableCustomCell.h"
#import "HXCycleCellModel.h"
#import "SelfSizeTools.h"
#import "HXTablePlayerCell.h"
#import "HXTodayPlayerWP.h"
#import "HXTableCustonPlayerCell.h"
#import "HXTalentCustomCell.h"
#import "HXTalentCell.h"
#import "HXGoodFoodTopicCell.h"
#import "HXCycleCellBigModel.h"
#import "HXPlayerCollectionCell.h"
#import "HXCustomBigModel.h"
#import "HXCustomModel.h"
#import "HXCustomTitlesModel.h"
#import "HXSelecedMadeCell.h"
#import "HXCycleImageVC.h"
#import "HXCustomVideoVC.h"
#import "HXDetailVideoVC.h"
#import "HXDetailVideoTCell.h"
#import "HXMaterialsVC.h"
#import "HXLinkModel.h"
#import "HXCachTools.h"
#import "HXMaterPersonVC.h"
#define kTableView @"tableView"
#define kCycleView @"cycleCell"
#define kTableCustomCell @"tablePlayerCell"
#define kTableTalentCustom @"talents"
#define kTableGoodFood @"reuseGoodFood"
#define kSelected @"select"
@interface CommandViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *headerView;
/**
 *  轮播图
 */
@property (nonatomic, strong) HX_CycleImage *hx_cycleImage;
/**
 *  轮播图模型数组
 */
@property (nonatomic, strong) NSMutableArray *arrCycleImage;
/**
 *  滚动cell模型数组
 */
@property (nonatomic, strong) NSMutableArray *arrCycleCell;
/**
 *  标题数组
 */
@property (nonatomic, strong) NSMutableArray *arrTitle;
/**
 *  todayNew(PlayerController)模型数组
 */

@property (nonatomic, strong) NSMutableArray *arrTodayNew;
/**
 *  title数据
 */
@property (nonatomic, strong) NSMutableArray *arrTodayTitle;
/**
 *  detail数据
 */
@property (nonatomic, strong) NSMutableArray *arrTodayDetail;

/**
 *  视频模型数组
 */
@property (nonatomic, strong) NSMutableArray *arrVideo;
/**
 *  透视图Lable
 */
@property (nonatomic, strong) UILabel *lableSectionHeader;
/**
 *  全部数据
 */
@property (nonatomic, strong) NSMutableArray *arrAllData;
/**
 *  数组总数据
 */
@property (nonatomic, strong) NSMutableArray *arrDataSource;
/**
 *  lableDetail
 */
@property (nonatomic, strong) NSMutableArray *arrDetail;
/**
 *  titile
 */
@property (nonatomic, strong) NSMutableArray *titles;
/**
 *  推荐达人Titles
 */
@property (nonatomic, strong) NSMutableArray *arrCommandTitles;
/**
 *  link数组源
 */
@property (nonatomic, strong) NSMutableArray *arrLink;
@end

@implementation CommandViewController

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.view layoutIfNeeded];
    self.navigationController.navigationBarHidden = NO;
}
- (NSMutableArray *)arrCommandTitles {
    if (!_arrCommandTitles) {
        _arrCommandTitles = [NSMutableArray array];
    }
    return _arrCommandTitles;
}
- (NSMutableArray *)titles {
    if (!_titles) {
        _titles = [NSMutableArray array];
    }
    return _titles;
}
- (NSMutableArray *)arrDetail {
    if (!_arrDetail) {
        _arrDetail = [NSMutableArray array];
    }
    return _arrDetail;
}
- (NSMutableArray *)arrLink {
    if (!_arrLink) {
        _arrLink = [NSMutableArray array];
    }
    return _arrLink;
}

- (NSMutableArray *)arrDataSource {
    if (!_arrDataSource) {
        _arrDataSource = [NSMutableArray array];
    }
    return _arrDataSource;
}

- (NSMutableArray *)arrAllData {
    if (!_arrAllData) {
        _arrAllData = [NSMutableArray array];
    }
    return _arrAllData;
}
- (NSMutableArray *)arrVideo {
    if (!_arrVideo) {
        _arrVideo = [NSMutableArray array];
    }
    return _arrVideo;
}
- (NSMutableArray *)arrTodayTitle {
    if (!_arrTodayTitle) {
        _arrTodayTitle = [NSMutableArray array];
    }
    return _arrTodayTitle;
}
- (NSMutableArray *)arrTodayDetail {
    if (!_arrTodayDetail) {
        _arrTodayDetail = [NSMutableArray array];
    }
    return _arrTodayDetail;
}
- (NSMutableArray *)arrTodayNew {
    if (!_arrTodayNew) {
        _arrTodayNew = [NSMutableArray array];
    }
    return _arrTodayNew;
}
- (NSMutableArray *)arrTitle {
    if (!_arrTitle) {
        _arrTitle = [NSMutableArray array];
    }
    return _arrTitle;
}
- (NSMutableArray *)arrCycleImage {
    if (!_arrCycleImage) {
        _arrCycleImage = [NSMutableArray array];
    }
    return _arrCycleImage;
}
- (NSMutableArray *)arrCycleCell {
    if (!_arrCycleCell) {
        _arrCycleCell = [NSMutableArray array];
    }
    return _arrCycleCell;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.arrAllData = [NSMutableArray array];
    [self getNetWorkingModel];
    [self creatTableView];

}
- (void)getNetWorkingModel {
    NSString *url = @"http://api.izhangchu.com";
    NSString *body = @"methodName=SceneHome&version=4.40&";
    NSDictionary *dicHeader =
    @{@"Content-Type" : @"application/x-www-form-urlencoded; charset=UTF-8",
      @"User-Agent" : @"Dalvik/1.6.0 (Linux; U; Android 4.3; R6007 Build/JLS36C)zhangchuAPPforAndroid4.4.0",
      @"Host" : @"api.izhangchu.com",
      @"Connection" : @"Keep-Alive", @"Accept-Encoding" : @"gzip"};
    [HXNetTool postNetWithUrl:url body:body BodyStyle:HXBodyString Header:dicHeader Response:HXJSON Success:^(id result) {
        NSDictionary *dicResult = result;
//        [HXCachTools archiverObject:dicResult ByKey:@"caches" WithPath:@"hxcach.plist"];
        NSDictionary *dicData = dicResult[@"data"];
        for (NSDictionary *dicBanner in dicData[@"banner"]) {
            HXFoodCycleModel *hxModel = [HXFoodCycleModel ModelWithDic:dicBanner];
            [self.arrCycleImage addObject:hxModel.banner_picture];
        }
        NSArray *arrWidgetList = dicData[@"widgetList"];
        for (NSDictionary *dic in arrWidgetList) {
            [self.arrTitle addObject:dic[@"title"]];
        }
        NSDictionary *dicOne = arrWidgetList[1];
        for (NSDictionary *dicWidget_data in dicOne[@"widget_data"]) {
            [self.arrCycleCell addObject:[HXCycleCellModel ModelWithDic:dicWidget_data]];
        }
        NSDictionary *dicTwo = arrWidgetList[2];
        for (NSDictionary *dicToday in dicTwo[@"widget_data"]) {
            HXCycleCellModel *modelToday = [HXCycleCellModel ModelWithDic:dicToday];
            if ([modelToday.type isEqualToString:@"image"]) {
                [self.arrTodayNew addObject:modelToday.content];
            }
            if ([modelToday.type isEqualToString:@"video"]) {
                [self.arrVideo addObject:modelToday.content];
            }
            if (![modelToday.link isEqualToString:@""]) {
                [self.arrLink addObject:modelToday.link];
            }
            if ([modelToday.type isEqualToString:@"text"]) {
                if ([modelToday.ID integerValue] % 2 == 0) {
                    [self.arrTodayTitle addObject:modelToday.content];
                } else {
                    [self.arrTodayDetail addObject:modelToday.content];
                }
            }
        }
        NSString *first = [self.arrCycleImage firstObject];
        [self.arrCycleImage addObject:first];
        NSString *last = [self.arrCycleImage lastObject];
        [self.arrCycleImage insertObject:last atIndex:0];
        self.hx_cycleImage.arrDataSource = self.arrCycleImage;
        NSArray *arrList = dicData[@"widgetList"];
        NSInteger number = 0;
        for (NSDictionary *dic in arrList) {
            if (![dic[@"widget_data"] isKindOfClass:NSClassFromString(@"NSNull")]) {
                HXCycleCellBigModel *mdoel = [HXCycleCellBigModel ModelWithDic:dic];
                [self.titles addObject:mdoel];
            }
            HXCycleCellBigModel *modelBig = [[HXCycleCellBigModel alloc] init];
            modelBig.desc = dic[@"desc"];
            [self.arrDetail addObject:modelBig];
            if (![dic[@"widget_data"] isKindOfClass:NSClassFromString(@"NSNull")]) {
                NSMutableDictionary *MutableDic = [NSMutableDictionary dictionary];
                NSMutableArray *arrOne = [NSMutableArray array];
                NSMutableArray *arrTwo = [NSMutableArray array];
                NSMutableArray *arrThree = [NSMutableArray array];
                [MutableDic setObject:[NSString stringWithFormat:@"%ld", number] forKey:@"number"];
                [MutableDic setObject:arrTwo forKey:@"widget_command"];
                [MutableDic setObject:arrOne forKey:@"widget_data"];
                [MutableDic setObject:arrThree forKey:@"widget_Link"];
                [self.arrAllData addObject:MutableDic];
                for (NSDictionary *dicSmall in dic[@"widget_data"]) {
                    HXCycleCellModel *smallModle = [HXCycleCellModel ModelWithDic:dicSmall];
                    NSMutableDictionary *imageDic = [NSMutableDictionary dictionary];
                    NSMutableDictionary *textDic = [NSMutableDictionary dictionary];
                    NSMutableDictionary *linkDic = [NSMutableDictionary dictionary];
                    if ([smallModle.type isEqualToString:@"image"]) {
                        [imageDic setObject:smallModle.content forKey:smallModle.type];
                        NSDictionary *dicLast = [_arrAllData lastObject];
                        [[dicLast objectForKey:@"widget_data"] addObject:imageDic];
                    }
                    if ([smallModle.type isEqualToString:@"text"]) {
                        smallModle.content = [NSString stringWithFormat:@"%@", smallModle.content];
                        [textDic setObject:smallModle.content forKey:smallModle.type];
                        NSDictionary *dicLat =[_arrAllData lastObject];
                        [dicLat[@"widget_command"] addObject:textDic];
                    }
                    if (smallModle.link.length > 0) {
                        [linkDic setObject:smallModle.link forKey:@"link"];
                        NSDictionary *link = [_arrAllData lastObject];
                        [link[@"widget_Link"] addObject:linkDic];
                    }
                }
                number++;
            }
        }
        for (NSDictionary *dicDta in self.arrAllData) {
            HXCustomBigModel *model = [HXCustomBigModel ModelWithDic:dicDta];
            [self.arrDataSource addObject:model];
        }
        [_tableView reloadData];
    } Failure:^(NSError *error) {
       NSDictionary *dicResult = [HXCachTools unarchiverObjectByKey:@"caches" WithPath:@"hxcach.plist"];
        NSDictionary *dicData = dicResult[@"data"];
        for (NSDictionary *dicBanner in dicData[@"banner"]) {
            HXFoodCycleModel *hxModel = [HXFoodCycleModel ModelWithDic:dicBanner];
            [self.arrCycleImage addObject:hxModel.banner_picture];
        }
        NSArray *arrWidgetList = dicData[@"widgetList"];
        for (NSDictionary *dic in arrWidgetList) {
            [self.arrTitle addObject:dic[@"title"]];
        }
        NSDictionary *dicOne = arrWidgetList[1];
        for (NSDictionary *dicWidget_data in dicOne[@"widget_data"]) {
            [self.arrCycleCell addObject:[HXCycleCellModel ModelWithDic:dicWidget_data]];
        }
        NSDictionary *dicTwo = arrWidgetList[2];
        for (NSDictionary *dicToday in dicTwo[@"widget_data"]) {
            HXCycleCellModel *modelToday = [HXCycleCellModel ModelWithDic:dicToday];
            if ([modelToday.type isEqualToString:@"image"]) {
                [self.arrTodayNew addObject:modelToday.content];
            }
            if ([modelToday.type isEqualToString:@"video"]) {
                [self.arrVideo addObject:modelToday.content];
            }
            if (![modelToday.link isEqualToString:@""]) {
                [self.arrLink addObject:modelToday.link];
            }
            if ([modelToday.type isEqualToString:@"text"]) {
                if ([modelToday.ID integerValue] % 2 == 0) {
                    [self.arrTodayTitle addObject:modelToday.content];
                } else {
                    [self.arrTodayDetail addObject:modelToday.content];
                }
            }
        }
        NSString *first = [self.arrCycleImage firstObject];
        [self.arrCycleImage addObject:first];
        NSString *last = [self.arrCycleImage lastObject];
        [self.arrCycleImage insertObject:last atIndex:0];
        self.hx_cycleImage.arrDataSource = self.arrCycleImage;
        NSArray *arrList = dicData[@"widgetList"];
        NSInteger number = 0;
        for (NSDictionary *dic in arrList) {
            if (![dic[@"widget_data"] isKindOfClass:NSClassFromString(@"NSNull")]) {
                HXCycleCellBigModel *mdoel = [HXCycleCellBigModel ModelWithDic:dic];
                [self.titles addObject:mdoel];
            }
            HXCycleCellBigModel *modelBig = [[HXCycleCellBigModel alloc] init];
            modelBig.desc = dic[@"desc"];
            [self.arrDetail addObject:modelBig];
            if (![dic[@"widget_data"] isKindOfClass:NSClassFromString(@"NSNull")]) {
                NSMutableDictionary *MutableDic = [NSMutableDictionary dictionary];
                NSMutableArray *arrOne = [NSMutableArray array];
                NSMutableArray *arrTwo = [NSMutableArray array];
                NSMutableArray *arrThree = [NSMutableArray array];
                [MutableDic setObject:[NSString stringWithFormat:@"%ld", number] forKey:@"number"];
                [MutableDic setObject:arrTwo forKey:@"widget_command"];
                [MutableDic setObject:arrOne forKey:@"widget_data"];
                [MutableDic setObject:arrThree forKey:@"widget_Link"];
                [self.arrAllData addObject:MutableDic];
                for (NSDictionary *dicSmall in dic[@"widget_data"]) {
                    HXCycleCellModel *smallModle = [HXCycleCellModel ModelWithDic:dicSmall];
                    NSMutableDictionary *imageDic = [NSMutableDictionary dictionary];
                    NSMutableDictionary *textDic = [NSMutableDictionary dictionary];
                    NSMutableDictionary *linkDic = [NSMutableDictionary dictionary];
                    if ([smallModle.type isEqualToString:@"image"]) {
                        [imageDic setObject:smallModle.content forKey:smallModle.type];
                        NSDictionary *dicLast = [_arrAllData lastObject];
                        [[dicLast objectForKey:@"widget_data"] addObject:imageDic];
                    }
                    if ([smallModle.type isEqualToString:@"text"]) {
                        smallModle.content = [NSString stringWithFormat:@"%@", smallModle.content];
                        [textDic setObject:smallModle.content forKey:smallModle.type];
                        NSDictionary *dicLat =[_arrAllData lastObject];
                        [dicLat[@"widget_command"] addObject:textDic];
                    }
                    if (smallModle.link.length > 0) {
                        [linkDic setObject:smallModle.link forKey:@"link"];
                        NSDictionary *link = [_arrAllData lastObject];
                        [link[@"widget_Link"] addObject:linkDic];
                    }
                }
                number++;
            }
        }
        for (NSDictionary *dicDta in self.arrAllData) {
            HXCustomBigModel *model = [HXCustomBigModel ModelWithDic:dicDta];
            [self.arrDataSource addObject:model];
        }
        
    }];
}
- (void)creatTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 110) style:0];
    self.hx_cycleImage = [[HX_CycleImage alloc] init];
    _hx_cycleImage.HX_height = 150;
    _hx_cycleImage.backgroundColor = [UIColor whiteColor];
    self.tableView.tableHeaderView = _hx_cycleImage;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = 0;
    [self.view addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"HXCommandCustomCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"reuse"];
    [_tableView registerClass:[HXTableCustomCell class] forCellReuseIdentifier:kTableView];
    [_tableView registerClass:[HXTablePlayerCell class] forCellReuseIdentifier:kCycleView];
    [_tableView registerClass:[HXTableCustonPlayerCell class] forCellReuseIdentifier:kTableCustomCell];
    [_tableView registerClass:[HXTalentCell class] forCellReuseIdentifier:kTableTalentCustom];
    [_tableView registerNib:[UINib nibWithNibName:@"HXGoodFoodTopicCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kTableGoodFood];
    [_tableView registerClass:[HXSelecedMadeCell class] forCellReuseIdentifier:kSelected];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _arrTitle.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    } else if (section == 6) {
        return 1;
    } else if (section == 8) {
        return 2;
    } else {
        return 1;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        HXCommandCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
        cell.btnBlock = ^(UIButton *btn) {
            if (btn == cell.newsPerson) {
                HXNewPersonVC *newsView = [[HXNewPersonVC alloc] init];
                [self.navigationController pushViewController:newsView animated:YES];
            } else if (btn == cell.foodMade) {
                HXFoodMadeVC *foodMadeVc = [[HXFoodMadeVC alloc] init];
                [self.navigationController pushViewController:foodMadeVc animated:YES];
            } else if (btn == cell.menuBtn) {
                HXScenceMenuVC *scence = [[HXScenceMenuVC alloc] init];
                [self.navigationController pushViewController:scence animated:YES];
            } else if (btn == cell.GuessLike) {
                HXGuessLikeVC *guess = [[HXGuessLikeVC alloc] init];
                [self.navigationController pushViewController:guess animated:YES];
            } else {
                HXSearchBtnVC *searBtn = [[HXSearchBtnVC alloc] init];
                [self.navigationController pushViewController:searBtn animated:YES];
            }
        };
        return cell;
    } else if (indexPath.section == 1) {
        HXTableCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableView];
        cell.cycleModel = self.arrCycleCell;
        cell.item = ^(NSInteger row) {
            HXCycleImageVC *cycleImage = [[HXCycleImageVC alloc] init];
            cycleImage.netId = [self.arrCycleCell[row] link];
            [self.navigationController pushViewController:cycleImage animated:YES];
        };
        return cell;
    } else if (indexPath.section == 2) {
        HXTablePlayerCell *cell = [tableView dequeueReusableCellWithIdentifier:kCycleView];
        cell.backgroundColor = COLORAUTO;
        cell.arrToday = self.arrTodayNew;
        cell.arrTitle = self.arrTodayTitle;
        cell.arrDetail = self.arrTodayDetail;
        cell.item = ^(NSInteger row) {
            HXDetailVideoVC *video = [[HXDetailVideoVC alloc] init];
            video.dishes_id = self.arrLink[row];
            [self.navigationController pushViewController:video animated:YES];
        };
        return cell;
    } if (indexPath.section == 5) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"dfds"];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:3 reuseIdentifier:@"dfds"];
        }
        return cell;
    } else if (indexPath.section == 6) {
        HXTalentCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableTalentCustom];
        cell.rows = ^(NSInteger row) {
            HXMaterPersonVC *maters = [[HXMaterPersonVC alloc] init];
            [self.navigationController pushViewController:maters animated:YES];
        };
        HXCustomBigModel *bigModel = self.arrDataSource[indexPath.section - 1];
        cell.arrImageHeader = bigModel.widget_data;
        cell.titles = bigModel.widget_command;
        return cell;
    }   else if (indexPath.section == 7) {
        HXSelecedMadeCell *selectMade = [tableView dequeueReusableCellWithIdentifier:kSelected];
        HXCustomBigModel *bigModel = self.arrDataSource[indexPath.section - 1];
        selectMade.arrImage = bigModel.widget_data;
        selectMade.item = ^(NSInteger row) {
            HXMaterialsVC *materials = [[HXMaterialsVC alloc] init];
            HXLinkModel *link = bigModel.widget_Link[2 * row];
            materials.netId = link.link;
            [self.navigationController pushViewController:materials animated:YES];
        };
        selectMade.arrTitles = bigModel.widget_command;
        selectMade.lableDetail.text = [self.arrDetail[indexPath.section] desc];
        return selectMade;
    } else if (indexPath.section == 8) {
        HXGoodFoodTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableGoodFood];
        HXCustomBigModel *bigModel = self.arrDataSource[indexPath.section - 1];
        cell.cusModel = bigModel.widget_data[indexPath.row];
        if (indexPath.row == 0) {
            cell.labelName.text = [[bigModel.widget_command objectAtIndex:0] text];
            cell.labelDetail.text = [[bigModel.widget_command objectAtIndex:1] text];
        } else {
            cell.labelName.text = [[bigModel.widget_command objectAtIndex:2] text];
            cell.labelDetail.text = [[bigModel.widget_command objectAtIndex:3] text];
        }
        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    } else
        if (indexPath.section == 5) {
            NSLog(@"%ld", indexPath.section);
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"dfd"];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:3 reuseIdentifier:@"dfd"];
            }
            return cell;
        } else {
            HXTableCustonPlayerCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableCustomCell];
            HXCustomBigModel *model = self.arrDataSource[indexPath.section];
            cell.arrCustom = model.widget_data;
            
            cell.labelDetail.text = [self.arrDetail[indexPath.section] desc];
            HXCycleCellBigModel *bigModel = self.titles[indexPath.section];
            cell.titles = [bigModel.arrWidget_data mutableCopy];
            cell.item = ^(NSInteger row) {
                if (row == 0) {
                    HXCustomVideoVC *video = [[HXCustomVideoVC alloc] init];
                    video.netId = [model.widget_Link[row] link];
                    [self.navigationController pushViewController:video animated:YES];
                } else {
                    HXDetailVideoVC *detailVideo = [[HXDetailVideoVC alloc] init];
                    detailVideo.dishes_id = [model.widget_Link[row] link];
                    
                    [self.navigationController pushViewController:detailVideo animated:YES];
                }
            };
            return cell;
        }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0 || section == 1) {
        return nil;
    } else if (section == 5) {
        UIView *viewTile = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        viewTile.backgroundColor = [UIColor colorWithRed:0.88 green:0.88 blue:0.88 alpha:1.00];
        self.lableSectionHeader = [[UILabel alloc] init];
        _lableSectionHeader.text = _arrTitle[section];
        _lableSectionHeader.HX_height = 80;
        _lableSectionHeader.HX_width = [SelfSizeTools selfSizeHeightWithString:_arrTitle[section] height:80 Font:[UIFont systemFontOfSize:17]];
        _lableSectionHeader.centerX = viewTile.centerX;
        UIImageView *imageTitle = [[UIImageView alloc] init];
        imageTitle.image = [UIImage imageNamed:@"cycleCellRight"];
        imageTitle.HX_height = 15;
        imageTitle.HX_width = 15;
        imageTitle.HX_x = _lableSectionHeader.centerX + _lableSectionHeader.HX_width / 2 + imageTitle.HX_width / 2 + 15;
        imageTitle.centerY = _lableSectionHeader.centerY;
        [viewTile addSubview:_lableSectionHeader];
        [viewTile addSubview:imageTitle];
        return viewTile;
    } else {
        UIView *viewTile = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        self.lableSectionHeader = [[UILabel alloc] init];
        _lableSectionHeader.text = _arrTitle[section];
        _lableSectionHeader.HX_height = 50;
        _lableSectionHeader.HX_width = [SelfSizeTools selfSizeHeightWithString:_arrTitle[section] height:50 Font:[UIFont systemFontOfSize:17]];
        _lableSectionHeader.centerX = viewTile.centerX;
        UIImageView *imageTitle = [[UIImageView alloc] init];
        imageTitle.image = [UIImage imageNamed:@"cycleCellRight"];
        imageTitle.HX_height = 15;
        imageTitle.HX_width = 15;
        imageTitle.HX_x = _lableSectionHeader.centerX + _lableSectionHeader.HX_width / 2 + imageTitle.HX_width / 2 + 15;
        imageTitle.centerY = _lableSectionHeader.centerY;
        [viewTile addSubview:_lableSectionHeader];
        [viewTile addSubview:imageTitle];
        return viewTile;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 8) {
        HXTodayPlayerWP *today = [[HXTodayPlayerWP alloc] init];
        HXCustomBigModel *bigModel = self.arrDataSource[indexPath.section - 1];
        if (indexPath.row == 0) {
            HXLinkModel *link = bigModel.widget_Link[indexPath.row];
            today.todayUrl = link.link;
            today.title = [bigModel.widget_command[0] text];
            [self.navigationController pushViewController:today animated:YES];
        } else {
            HXLinkModel *link = bigModel.widget_Link[indexPath.row];
            today.todayUrl = link.link;
            today.title = [bigModel.widget_command[2] text];
            [self.navigationController pushViewController:today animated:YES];
        }
    }
  
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0 || section == 1) {
        return 0;
    } else if (section == 5) {
        return 80;
    } else {
        return 50;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 150;
    } else if(indexPath.section == 1) {
        return 80;
    } else if (indexPath.section == 2) {
        return 180;
    } if (indexPath.section == 5) {
        return 0;
    } else if (indexPath.section == 6) {
        return 315;
    } else if (indexPath.section == 8) {
        return 200;
    } else {
        return 230;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
